home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Basic Source Code
/
Visual Basic Source Code.iso
/
vbsource
/
powervww
/
pvstddlg.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1998-01-05
|
20KB
|
877 lines
// ____________________________________________________
// | |
// | Project: POWER VIEW INTERFACE |
// | File: PVSTDDLG.CPP |
// | Compiler: WPP386 (10.6) |
// | |
// | Subject: Standard dialog boxes implementation |
// | |
// | Author: Emil Dotchevski |
// |____________________________________________________|
//
// E-mail: zajo@geocities.com
// URL: http://www.geocities.com/SiliconValley/Bay/3577
#define uses_fcntl
#define uses_stdarg
#define uses_stdio
#define uses_string
#define uses_app
#define uses_desk
#define uses_dialog
#define uses_help
#define uses_icons
#define uses_input
#define uses_stddlg
#define uses_system
#define uses_txt
#define DECLARE_PVSTDDLG
#include "PVuses.h"
#undef DECLARE_PVSTDDLG
#define _ICON_NOTHING 1
#define _ICON_WARNING 2
#define _ICON_QUESTION 3
#define _ICON_INFO 4
uint test_file_exist( char *path )
{
int handle;
if( !_dos_open( path, O_RDONLY, &handle ) )
{
char s[_MAX_PATH];
_dos_close( handle );
strcpy( s, path );
fexpand( s ); min_path( s ); short_path( s, 29 );
_iwarning();
#ifdef CYR
return ync( "éÑ╖Ñ ▒║╣Ñ▒▓ó│óá ┤á⌐½ %s.\n\nçá¼┐¡á ¡á ▒║╣Ñ▒▓ó│óá╣¿┐ ┤á⌐½?", s );
#else
return ync( "File %s already exists.\n\nReplace existing file?", s );
#endif
}
return 0;
}
//OPEN FILE DIALOG
static char dir[_MAX_DIR+_MAX_DRIVE];
static char filter[_MAX_FNAME];
static Tlist_box *files=NULL;
static Tlist_box *dirs;
static Tcombo_box *filters;
static Tcombo_box *drives;
static Tinput *item_name;
static Tdtext *show_dir;
static Tdtext *show_info;
static boolean new_file_fl;
static boolean overflow;
struct Tfile_rec
{
char attr;
uint time;
uint date;
long size;
};
static void get_info_str( Tfile_rec &d, char *result )
{
char m[14];
uint year;
char month, day, hours, minutes, seconds;
#ifndef CYR
char *am;
#endif
if( d.attr & _A_SUBDIR )
#ifdef CYR
strcpy( result, "ÅỬá " );
#else
strcpy( result, "Directory" );
#endif
else
sprintf( result, "%-9lu", d.size );
unpack_time( d.time, hours, minutes, seconds );
unpack_date( d.date, year, month, day );
if( month ) month--;
memcpy( m, months[month], 3 ); m[3] = 0;
#ifdef CYR
sprintf( result + 9, " %2d %s, %4d %2d:%02d", day, m, year, hours, minutes );
#else
if( hours < 12 )
am = "am";
else
{
am = "pm";
hours -= 12;
}
if( !hours ) hours = 12;
sprintf( result + 9, " %s %2d, %4d %2d:%02d%s", m, day, year, hours, minutes, am );
#endif
}
static void file_change( void )
{
char s[_MAX_PATH], *p;
int i;
Tfile_rec d;
if( !files->vcount ) return;
files->gettxt( files->vcurrent, s );
item_name->set_txt( s );
files->getdata( files->vcurrent, &d );
p = strchr( s, 0 );
for( i = 0; i < ( _MAX_FNAME + _MAX_EXT ); i++ )
*(p++) = ' ';
get_info_str( d, s + _MAX_FNAME + _MAX_EXT );
show_info->set_txt( s );
}
static void dir_change( void )
{
char s[_MAX_PATH], r[_MAX_PATH], *p;
int i;
Tfile_rec d;
if( !dirs->vcount ) return;
dirs->gettxt( dirs->vcurrent, s );
sprintf( r, "%s\\%s", s, filter );
item_name->set_txt( r );
dirs->getdata( dirs->vcurrent, &d );
p = strchr( s, 0 );
for( i = 0; i < ( _MAX_FNAME + _MAX_EXT ); i++ )
*(p++) = ' ';
get_info_str( d, s + _MAX_FNAME + _MAX_EXT );
show_info->set_txt( s );
}
static void reread( void )
{
struct find_t dir_info;
char tmp_drive[_MAX_DRIVE];
char tmp_path[_MAX_PATH];
char tmp_name[_MAX_FNAME];
char tmp_ext[_MAX_EXT];
char path[_MAX_PATH];
char *p;
int done;
uint index;
Tfile_rec fd;
item_name->get_txt( path );
while( ( p = strchr( path, ' ' ) ) != NULL )
strcpy( p, p+1 );
if( ( *path == 0 ) || ( ( path[0] != '\\' ) && ( path[1] != ':' ) ) )
{
strcpy( tmp_path, path );
strcpy( path, dir );
strcat( path, tmp_path );
}
fexpand( path );
_splitpath( path, tmp_drive, dir, tmp_name, tmp_ext );
if( ( *tmp_name != 0 ) || ( *tmp_ext != 0 ) )
{
strcpy( filter, tmp_name );
strcat( filter, tmp_ext );
}
strcpy( path, tmp_drive );
strcat( path, dir );
strcat( path, filter );
short_path( path, 48 );
show_dir->set_txt( path );
strcpy( path, dir );
strcpy( dir, tmp_drive );
strcat( dir, path );
strcpy( path, filter );
item_name->set_txt( path );
show_info->set_txt( "" );
for( ;; )
{
strcpy( tmp_path, dir );
strcat( tmp_path, filter );
files->clear();
critical_error();
for( done=_dos_findfirst(tmp_path,_A_NORMAL,&dir_info);
!done;
done=_dos_findnext(&dir_info) )
{
fd.attr = dir_info.attrib;
fd.time = dir_info.wr_time;
fd.date = dir_info.wr_date;
fd.size = dir_info.size;
_ldata( &fd ); files->add( dir_info.name );
}
files->sort();
files->top();
if( files->overflow ) overflow = 1;
strcpy( tmp_path, dir );
strcat( tmp_path, "*.*" );
dirs->clear();
for( done=_dos_findfirst(tmp_path,_A_SUBDIR,&dir_info);
!done;
done=_dos_findnext(&dir_info) )
if( ( strcmp( dir_info.name, "." ) && ( dir_info.attrib & _A_SUBDIR ) ) )
{
fd.attr = dir_info.attrib;
fd.time = dir_info.wr_time;
fd.date = dir_info.wr_date;
fd.size = dir_info.size;
_ldata( &fd ); dirs->add( dir_info.name );
}
dirs->sort();
dirs->top();
if( dirs->overflow ) overflow = 1;
sprintf( tmp_path, "[-%c-]", tmp_drive[0] );
if( ( index = drives->findft( tmp_path ) ) != (uint) -1 )
drives->set_data( index );
if( done!=18 )
if( critical_error() )
{
files->clear();
dirs->clear();
if( drive_error( tmp_drive[0] ) ) continue;
}
else
{
_terror();
ok( "Cant read disk directory.\n\n(Does such directory exist?)" );
}
break;
}
if( current() == dirs )
dir_change();
else
if( current() == files )
file_change();
else
focus( files );
modal_broadcast( cmDLG_RESET );
}
static void open_file_handler( Titem *p )
{
char s[_MAX_PATH], *n;
if( p == files )
file_change();
else
if( p == dirs )
dir_change();
else
if( p == drives )
{
drives->get_data( s );
*dir = s[2];
strcpy( dir+1, ":\\" );
item_name->set_txt( "" );
reread();
}
else
if( p == filters )
{
filters->get_data( s );
n = strchr( s, '(' ) + 1;
*strchr( n, ')' ) = 0;
item_name->set_txt( n );
reread();
}
}
static boolean open_file_validator( uint x )
{
char path[_MAX_PATH];
char tmp_drive[_MAX_DRIVE];
char tmp_dir[_MAX_DIR];
char tmp_name[_MAX_FNAME];
char tmp_ext[_MAX_EXT];
char *l;
uint xx;
switch( x )
{
case cmVALID:
return !overflow;
case cmOK:
item_name->get_txt( path );
l = strchr( path, 0 );
if( *(l - 1) == ':' )
{
*(l++) = '\\';
*l = 0;
}
if( ( strchr( path, '*') == NULL ) && ( strchr( path, '?' ) == NULL ) && ( *( strchr( path, 0 ) - 1 ) != '\\' ) )
{
_splitpath( path, tmp_drive, tmp_dir, tmp_name, tmp_ext );
if( !*tmp_dir && !*tmp_drive )
{
strcpy( tmp_dir, dir+2 );
*tmp_drive = *dir;
}
if( !*tmp_ext ) strcpy( tmp_ext, strchr( filter, '.' ) );
if( ( strchr( tmp_ext, '*' ) != NULL ) || ( strchr( tmp_ext, '?' ) != NULL ) ) strcpy( tmp_ext, "." );
_makepath( path, tmp_drive, tmp_dir, tmp_name, tmp_ext );
fexpand( path );
if( new_file_fl && (xx=test_file_exist(path)) )
{